---
output:
  pdf_document: default
  word_document: default
  html_document: default
---

# README

## Overview

The code in this replication package replicates Figures 2.1 and 6.1-6.4. 
The replicator should expect the code to run for about 4.5 hours.

## Data Availability and Provenance Statements

- [x] This paper does not involve analysis of external data (i.e., no data are used or the only data are generated by the authors via simulation in their code).

## Computational requirements

### Software Requirements

- R 4.5.2
  - `tidyverse` (2.0.0)
  - `latex2exp` (0.9.6)
  - `mvtnorm` (1.3.3)
  - `stats` (4.5.2) 

### Controlled Randomness

While the code uses seeds to control randomness, this may not always be tightly controlled. The results are expected to change slightly between various machines
due to differences in package versions. Also, the computing time reported in the simulations is expected to vary across different machines. 

### Memory, Runtime, Storage Requirements

#### Summary

Approximate time needed to reproduce the analyses on a standard 2019 desktop machine:

- [ ] <10 minutes
- [ ] 10-60 minutes
- [ ] 1-2 hours
- [x] 2-8 hours
- [ ] 8-24 hours
- [ ] 1-3 days
- [ ] 3-14 days
- [ ] > 14 days

Approximate storage space needed:

- [ ] < 25 MBytes
- [ ] 25 MB - 250 MB
- [x] 250 MB - 2 GB
- [ ] 2 GB - 25 GB
- [ ] 25 GB - 250 GB
- [ ] > 250 GB

- [ ] Not feasible to run on a desktop machine, as described below.

#### Details

The code was last run on a 14 Core (M4 Max) Mac Based Laptop with 36GB of RAM and 1TB of fast local storage. Computation took approximately 4.5 hours. 

## Description of programs/code

The programs are organized into four R Markdown files.

- `Empirical_illustration.Rmd` will replicate the two-subplots of Figure 2.1. 

- `Linear_boundary.Rmd` will replicate the two sub-plots of Figure 6.1. 

- `Group_Sequential_Trials.Rmd` will replicate the two sub-plots of Figure 6.2. 

- `Bandit_experiments.Rmd` will replicate Figure 6.3 and the two sub-plots of Figure 6.4. 


### License for Code

The code is licensed under an MIT license.

## Instructions to Replicators

The replication package contains four R Markdown (.Rmd files). Each Markdown file replicates the 
figures from a particular sub-section of the paper.

Use the optional file `Packages and directory_SCRIPT.R` to install the necessary R packages. 
The working directory for the folder can also be set there. 
\
&nbsp;

- `Empirical_illustration.Rmd`:

    - The code generates the two-subplots of Figure 2.1.
    
    - Run the code in its entirety.
    
    - This generates the sub-plots of Figure 2.1, saved as two png files:
      i. `Size_one_armed_bandit.png`
      ii. `Power_envelope_one_armed_bandit.png`.
\
&nbsp; 

- `Linear_boundary.Rmd`:

    - The code generates the two-subplots of Figure 6.1.
    
    - Run the code in its entirety.
    
    - This generates the sub-plots of Figure 6.1, saved as two png files:
      i. `Size.png`
      ii. `Power envelope.png`.
\
&nbsp;  

- `Group_Sequential_Trials.Rmd`: 

    - The code generates the two-subplots of Figure 6.2.
    
    - Run the code in its entirety.
    
    - This generates the sub-plots of Figure 6.2, saved as two png files:
      i. `Critical_value_thresholds_GST.png`
      ii. `Size_GST.png.png`.
 \
&nbsp; 

- `Bandit_experiments.Rmd`: 

    - The code generates Figure 6.3 and the two-subplots of Figure 6.4. 
    
    - Run the code in its entirety.
    
    - This generates Figure 6.3 and the two sub-plots of Figure 6.2, saved as three png files:
      i. `Power_envelope_TS.png`
      ii. `Power_comparison_TS.png` 
      iii. `Power_comparison_TS2.png`
\
&nbsp; 

## List of tables and programs

The provided code reproduces:

- [ ] All numbers provided in text in the paper
- [x] All tables and figures in the paper
- [ ] Selected tables and figures in the paper, as explained and justified below.


| Figure #  | Program                             | Line # | Output file                         
|-----------|-------------------------------------|--------|-------------------------------------|
| Figure 2.1| Empirical_illustration.Rmd          | 432    | Size_one_armed_bandit.png           |
|           |                                     | 465    | Power_envelope_one_armed_bandit.png |                                           |
| Figure 6.1| Linear_boundary.Rmd                 | 142    | Size.png                            |
|           |                                     | 212    | Power envelope.png                  |
| Figure 6.2| Group_Sequential_Trials.Rmd         | 75     | Critical_value_thresholds_GST.png   |
|           |                                     | 155    | Size_GST.png                        |
| Figure 6.3| Bandit_experiments.Rmd              | 105    | Power_envelope_TS.png               |
| Figure 6.4| Bandit_experiments.Rmd              | 183    | Power_comparison_TS.png             |
|           |                                     | 269    | Power_comparison_TS2.png            |